package com.itheima.dao;

import com.itheima.domain.Account;
import com.itheima.domain.Trade;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

public interface UserDao {
    @Select("select * from account where accountID = #{accountID} and password = #{password}")
    Account login(Account account);

    @Select("select remaining from account where accountID = #{accountID} and password = #{password}")
    String selectBalance(@Param("accountID") String accountID,@Param("password") String password);

    @Select("select * from trade where tradeTime between #{startTime} and #{endTime} and accountID = #{accountID}")
    List<Trade> selectTransactions(@Param("startTime") Date startTime, @Param("endTime") Date endTime,@Param("accountID") String accountID);

    @Select("select remaining from account where accountID = #{accountID}")
    Integer selectMoney(String accountID);

    @Select("select * from account where accountID = #{toAccount}")
    Account selectAccountID(String toAccount);

    @Update("UPDATE account SET remaining = remaining+#{money} WHERE accountID = #{accountID}")
    void transfer(@Param("accountID") String accountID, @Param("money") double money);

    @Insert("insert into trade values (null,#{accountID},#{transferWay},#{toMoney},#{date},#{digest})")
    void addLog(@Param("accountID") String accountID,@Param("transferWay") String transferWay,@Param("toMoney") int toMoney,@Param("date") Date date,@Param("digest") String digest);

    @Insert("insert into trade values (null,#{accountID},#{tradeType},#{tradeMoney},#{tradeTime},#{tradeDigest})")
    void addTransterLog(Trade trade);
}
